<template>
	<view class="" style="width: 700rpx;margin: auto;padding: 20rpx;">
		<card :list='list' @buy='buy'></card>
		
		<u-loadmore :status="initial.status" v-if="list.length" />
	</view>
</template>

<script>
	import payway from '../../common/wxpay.js';
	import loader from '@/common/loadPage.js';
	import card from './component/card.vue'
	
	export default {
		components: {
					card
		},
		mixins: [loader],
		data() {
			return {
				list: [],
				initial: {
					geturl: "/api/index/card",
					parm: {
						store_id: ''
					},
					isPage: true
				},
			}
		},
		onLoad(option) {
			if (option.id) {
				this.initial.parm.store_id = option.id
			}
		},
		onShow() {
			this.getGoods().then(res=>{
				var arr= this.color(res);
				this.list=arr;
			})
		},
		methods: {
			color(params) {
				var colorList = ['to right, #FF6D8A,#FF4962', 'to right, #FFB916,#FE8F1E','to right, #7AC2FE,#3F96FF'];
				var colorList2 = [' #FF6D8A', '#FFB916',' #7AC2FE'];
				params.forEach((item,index)=>{
					item.color=colorList2[index % colorList2.length]
					item.bg=colorList[index % colorList.length]
				})
				return params
			},
			buy(item) {
				this.$u.post('/api/indent/buyCard', {
					card_id: item.id,
					store_id: this.id,
				}).then(res => {
					if (res == null) {
						this.$refs.uToast.show({
							title: '领取成功',
							type: 'success',

						})
					} else {
						var packages = res.package;
						var {
							noncestr,
							timestamp,
							signtype,
							paysign
						} = res
						payway.wx(timestamp, noncestr, packages, signtype, paysign).then(
							res => {
								this.$refs.uToast.show({
									title: '购买成功',
									type: 'success',
								})
							}).catch(err => {})
					}
				}).catch(err => {

				})


			},
		}
	}
</script>

<style>
	.list {
		padding: 20rpx;
		color: #fff;
		border-radius: 20rpx;
		margin: 20rpx auto;
		width: 700rpx;
	}

	.b {
		background: linear-gradient(94deg, #4BA6FF 0%, #0064C6 100%);
	}

	.g {
		background: linear-gradient(90deg, #21D676 0%, #0BBC75 100%);
	}

	.buy {
		padding: 7rpx 15rpx;
		background: #fff;
		border-radius: 20rpx;
		color: #0064C6;
		font-weight: bold;
	}
</style>
